package com.self.match.controller;

import com.lmax.disruptor.EventHandler;
import com.self.match.disruptor.OrderEvent;
import com.self.match.disruptor.OrderEventHandler;
import com.self.match.model.DepthItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version v1.0
 * @ClassName: MatchController
 * @Description:
 * @Author: Mac
 */
@RestController
public class MatchController {


    @Autowired
    private EventHandler<OrderEvent>[] eventHandlers;


    /**
     * @Title: 查询该交易对的盘口数据
     * @Description: 
     * @Param [symbol]
     * @Return java.util.Map<java.lang.String,java.util.List<com.self.match.model.DepthItemVo>>
     * @Author Mac
     * @Throws
     */
    @GetMapping("/match/depth")
    public Map<String, List<DepthItemVo>> querySymbolDepth(String symbol) {
        for (EventHandler<OrderEvent> eventHandler : eventHandlers){
            OrderEventHandler orderEventHandler = (OrderEventHandler)eventHandler;
            if (orderEventHandler.getOrderBooks().getSymbol().equals(symbol)){
                Map<String, List<DepthItemVo>> deptMap = new HashMap<>();
                deptMap.put("asks", orderEventHandler.getOrderBooks().getSellTradePlate().getItems());
                deptMap.put("bids", orderEventHandler.getOrderBooks().getBuyTradePlate().getItems());
                return deptMap;
            }
        }
        return null;
    }
}
